from utils.dbFunc import MySQLDB as mysql

"""
    def rollback(self):
        self.cursor.execute("ROLLBACK")
        self.conn.rollback()
"""


db = mysql()
res = db.fetchall('select * from tb_user where id = %s;',(1))
print(res)
db.close()


# 更新数据
db.update('users', {'age': 26}, 'name = %s', ('Alice',))
 
# 删除数据
db.delete('users', 'age < %s', (20,))

def update(self, table, data, condition):
    sets = ', '.join(['{} = %s'.format(k) for k in data])
    sql = 'UPDATE {table} SET {sets} WHERE {condition}'.format(table=table, sets=sets, condition=condition)
    self.execute(sql, tuple(data.values()))

def delete(self, table, condition):
    sql = 'DELETE FROM {table} WHERE {condition}'.format(table=table, condition=condition)
    self.execute(sql)